<template>
	<view class="query_content">
		<h3>成绩查询</h3>
		<el-form :model="ruleForm" :rules="rules" label-position="top" ref="ruleForm" label-width="100px"
			class="demo-ruleForm">
			<el-form-item label="姓名" prop="fullName">
				<el-input  v-model="ruleForm.fullName" rows="8" placeholder="请输入姓名"></el-input>
			</el-form-item>
			<el-form-item label="身份证号" prop="idNumber">
				<el-input  v-model="ruleForm.idNumber" rows="8" placeholder="请输入身份证号"></el-input>
			</el-form-item>
			<el-form-item label="职位" prop="PositionId">
				<el-select v-model="ruleForm.PositionId" placeholder="请选择职位" style="width: 100%;">
					<el-option v-for="item in educationLevelOption" :label="item.positionName" :value="item.id">
					</el-option>
				</el-select>
			</el-form-item>
		</el-form>
		<view class="position_footer flex aic jcsb">
			<el-button class="blue_btn" style="width: 100%;" type="primary" @click="submitForm('ruleForm')">查询
			</el-button>
		</view>
		<el-table :data="tableDataB" style="width: 100%;margin-top: 16px;" >
		    <el-table-column label="笔试成绩" align="center">
		      <el-table-column prop="fullName" label="姓名" align="center"/>
		      <el-table-column prop="idNumber" label="身份证号"  align="center" width="180px"/>
		      <el-table-column prop="writingTestingScore" label="笔试成绩"  align="center"/>
		      <el-table-column prop="writingTestingResult" label="笔试结果"  align="center"/>
		    </el-table-column>
		  </el-table>
		  <el-table :data="tableDataM" style="width: 100%;margin-top: 16px;" >
		      <el-table-column label="面试成绩" align="center">
		        <el-table-column prop="fullName" label="姓名" align="center"/>
		        <el-table-column prop="idNumber" label="身份证号"  align="center" width="180px"/>
				<!-- <el-table-column prop="idNumber" label="面试成绩"  align="center"/> -->
				<el-table-column prop="interviewScore" label="面试成绩"  align="center"/>
				<el-table-column prop="interviewResult" label="面试结果"  align="center" />
		      </el-table-column>
		    </el-table>
	</view>
</template>

<script>
	import {
		getscore,
	} from "@/api/my"
	import {getlist} from "@/api/index"
	export default {
		data() {
			return {
				ruleForm: {
					fullName: '',
					idNumber: ""
				},
				educationLevelOption:[],
				tableDataB:[],
				tableDataM:[],
				rules: {
					fullName: [{
						required: true,
						message: '请输入姓名',
						trigger: 'blur'
					}],
					idNumber: [{
						required: true,
						message: '请输入身份证号',
						trigger: 'blur'
					}, {
						pattern: /^\d{17}(\d|x)$/i,
						message: '身份证号格式不正确',
						trigger: 'blur'
					}],
					PositionId: [{
						required: true,
						message: '请选择职位',
						trigger: 'blur'
					}],
				}
			};
		},
		onLoad() {
			this.getlistApi()
		},
		methods: {
			getlistApi(){
				let params={
					pageNum:1,
					pageSize:1000000
				}
				getlist(params).then(res=>{
					console.log(res);
					this.educationLevelOption=res.rows
				})
			},
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						let obj = this.ruleForm
						console.log(obj);
						getscore(obj).then(res => {
							console.log(res);
							this.tableDataB=[]
							this.tableDataM=[]
							let obj1={
								fullName:this.ruleForm.fullName,
								idNumber:this.ruleForm.idNumber,
								writingTestingScore:res.data.writingTestingScore,
								writingTestingResult:res.data.writingTestingResult==0?"未通过":res.data.writingTestingResult==1?"通过":"无结果"
							}
							let obj2={
								fullName:this.ruleForm.fullName,
								idNumber:this.ruleForm.idNumber,
								// writingTestingScore:res.data.writingTestingScore,
								interviewScore:res.data.interviewScore,
								interviewResult:res.data.interviewResult==0?"未通过":res.data.interviewResult==1?"通过":"无结果"
							}
							
							if(obj1.writingTestingScore){
								this.tableDataB.push(obj1)
							}
							if(obj2.interviewResult){
								this.tableDataM.push(obj2)
							}
							
							uni.showToast({
								title: "查询成功",
								icon: 'success'
							})
						}).catch(res => {
							uni.showToast({
								title: res.msg,
								icon: 'error'
							})
						})
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			resetForm() {
				this.ruleForm.feedback="";
				this.ruleForm.feedbackOssIds="";
			},
		}
	}
</script>

<style lang="scss" scoped>
	.query_content {
		margin: auto;
		padding: 20px;
		max-width: 500px;
	}
</style>
